package com.stox.ui.javafx.core.mode;

import java.util.Locale;

import javafx.scene.control.ChoiceBox;
import javafx.util.StringConverter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

import com.stox.dto.enumeration.Mode;

@Component
public class ModeChoiceBox extends ChoiceBox<Mode> {
	
	@Autowired
	private void setMessageSource(final MessageSource messageSource){
		getItems().addAll(Mode.values());
		setConverter(new StringConverter<Mode>(){
			@Override
			public Mode fromString(String arg0) {
				return null;
			}
			
			@Override
			public String toString(Mode mode) {
				return messageSource.getMessage(mode.getCode(), null, Locale.getDefault());
			}
		});
		getSelectionModel().select(0);
	}
	
}
